package day01;

import lombok.extern.slf4j.Slf4j;

/**
 * 在java的线程的六种状态例子
 */
@Slf4j
public class TestState {
    public static void main(String[] args) {
        Thread t1 = new Thread("t1") {
            @Override
            public void run() {
                log.debug("running");
            }
        };


        Thread t2 = new Thread("t2") {
            @Override
            public void run() {
                while (true) {

                }
            }
        };
        t2.start();


        Thread t3 = new Thread("t3") {
            @Override
            public void run() {
                log.debug("running");
            }
        };
        t3.setPriority(10);
        t3.start();

        Thread t4 = new Thread("t4") {
            @Override
            public void run() {
                synchronized (TestState.class) {
                    try {
                        Thread.sleep(1000000);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
            }
        };
        t4.start();


        Thread t5 = new Thread("t5"){
            @Override
            public void run() {

                    try {
                        t2.join();
                    } catch (InterruptedException e){
                        e.printStackTrace();
                    }
                }

        };
        t5.start();

        Thread t6 = new Thread("t6") {
            @Override
            public void run() {
                synchronized (TestState.class) {
                    try {
                        Thread.sleep(100000);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
            }
        };

        t6.start();



        // log.debug出这六个线程的状态
        log.debug("t1 state:{}", t1.getState());
        log.debug("t2 state:{}", t2.getState());
        log.debug("t3 state:{}", t3.getState());
        log.debug("t4 state:{}", t4.getState());
        log.debug("t5 state:{}", t5.getState());
        log.debug("t6 state:{}", t6.getState());

    }
}
